package com.ysqcould.web.controller.allocation;


import com.ysqcould.allocation.domain.Poster;
import com.ysqcould.allocation.domain.WxList;
import com.ysqcould.allocation.domain.WxUserContacts;
import com.ysqcould.allocation.service.IWxUserContactsService;
import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 自动认证会员数据Controller
 * 
 * @author ruoyi
 * @date 2022-06-30
 */
@RestController
@RequestMapping("/allocation/wxContacts")
public class WxUserContactsController extends BaseController
{
    @Autowired
    private IWxUserContactsService wxUserContactsService;

    /**
     * 查询自动认证会员数据列表
     */
    @PreAuthorize("@ss.hasPermi('allocation:wxContacts:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxUserContacts wxUserContacts)
    {
        startPage();
        List<WxUserContacts> list = wxUserContactsService.selectWxUserContactsList(wxUserContacts);
        return getDataTable(list);
    }

    /**
     * 导出自动认证会员数据列表
     */
    @PreAuthorize("@ss.hasPermi('allocation:wxContacts:export')")
    @Log(title = "自动认证会员数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxUserContacts wxUserContacts)
    {
        List<WxUserContacts> list = wxUserContactsService.selectWxUserContactsList(wxUserContacts);
        ExcelUtil<WxUserContacts> util = new ExcelUtil<WxUserContacts>(WxUserContacts.class);
        util.exportExcel(response, list, "自动认证会员数据数据");
    }

    /**
     * 获取自动认证会员数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('allocation:wxContacts:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wxUserContactsService.selectWxUserContactsById(id));
    }

    /**
     * 新增自动认证会员数据
     */
    @PreAuthorize("@ss.hasPermi('allocation:wxContacts:add')")
    @Log(title = "自动认证会员数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxUserContacts wxUserContacts)
    {
        wxUserContacts.setAsId(getUserId());
        return toAjax(wxUserContactsService.insertWxUserContacts(wxUserContacts));
    }

    /**
     * 修改自动认证会员数据
     */
    @PreAuthorize("@ss.hasPermi('allocation:wxContacts:edit')")
    @Log(title = "自动认证会员数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxUserContacts wxUserContacts)
    {
        return toAjax(wxUserContactsService.updateWxUserContacts(wxUserContacts));
    }

    /**
     * 删除自动认证会员数据
     */
    @PreAuthorize("@ss.hasPermi('allocation:wxContacts:remove')")
    @Log(title = "自动认证会员数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wxUserContactsService.deleteWxUserContactsByIds(ids));
    }

    /**
     * 微信通讯录数据导入
     * @param file
     * @param updateSupport
     * @return
     * @throws Exception
     */
    @Log(title = "微信通讯录", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('allocation:wxContacts:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<WxUserContacts> util = new ExcelUtil<WxUserContacts>(WxUserContacts.class);
        List<WxUserContacts> wxList = util.importExcel(file.getInputStream());
        /*wxList.subList()*/
        String message = wxUserContactsService.importUser(wxList,updateSupport);
        return AjaxResult.success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<WxUserContacts> util = new ExcelUtil<WxUserContacts>(WxUserContacts.class);
        util.importTemplateExcel(response, "用户数据");
    }

    /**
     * 状态修改
     */
    @Log(title = "通信录", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody WxUserContacts contacts)
    {
        return toAjax(wxUserContactsService.updateStatus(contacts));
    }
}
